# coding:utf-8
import pymongo
from bson import ObjectId
from gridfs import GridFS

from app import db

tbVideo = db["video"]
testColl = db['dbTest']

# {timelines:[],keywords:[],posGrade:10,negGrade:20}

def addSentiment(id, timelines, keywords, posGrade, negGrade):
    sentiment = {'pos':posGrade, 'neg':negGrade}
    query = {"_id": ObjectId(id)}
    newvalues = {"$set": {"timelines": timelines,
                          "keywords":keywords,
                          "sentiment":sentiment}}
    tbVideo.update_one(query, newvalues)

# addSentiment("5c9c74c7ef3c9c3e80a5cc6d", [])

def readCaption(videoId):
    query = {"_id": ObjectId(videoId)}
    video = tbVideo.find_one(query)

    # print(video)
    return video['captionText'], video['captionExt']

if __name__ == '__main__':
    text, ext = readCaption("5ca1d1cbb5a2d4088463724a")
    print(text)
    print(ext)
    # readCaption("5ca1be11b5a2d40884637247")
